package com.rg1906.web;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.rg1906.entity.LoginUser;
import com.rg1906.entity.QuerygradeClass;
import com.rg1906.service.impl.StudentManageServiceImpl;
import com.rg1906.service.impl.StudentScoreServiceImpl;


@WebServlet("/StudentManage")
public class StudentManage extends HttpServlet {
	private static final long serialVersionUID = 1L;
	StudentScoreServiceImpl service1=new StudentScoreServiceImpl();
	StudentManageServiceImpl service=new StudentManageServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		LoginUser user = (LoginUser)session.getAttribute("user");
		int rid = user.getRid();//权限id   rid
		String loginName = user.getLoginName();//登录账号    学号
		String Gid=null;
		String Cid=null;
		
		String pageNumber;
		String pageSize;
		 pageNumber = request.getParameter("pageNumber");
		 pageSize = request.getParameter("pageSize");
		if(pageNumber==null||pageSize==null) {
			pageNumber="0";
			pageSize="3";
		}
		String likeName = request.getParameter("likeName");//模糊查询的名字
		String studentNum = request.getParameter("studentNum");//学号
		String gradeClazz = request.getParameter("gradeClazz");//班级
		String gradeName = request.getParameter("gradeName");//年级
		HashMap<String,Object> map = new HashMap<>();
		try {
			List<com.rg1906.entity.StudentManage> list = service.QueryStudent(pageNumber,pageSize,likeName,studentNum,gradeName,gradeClazz);
			Long total = service.getTotal(likeName,studentNum,gradeClazz,gradeName);
			map.put("rows", list);
			map.put("total", total);
			String jsonString = JSON.toJSONString(map);
			response.getWriter().print(jsonString);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
